const mongoose = require("mongoose");
const { Schema } = mongoose

const UsersSchema = mongoose.Schema(
    {
        id_user: {
            type: Number,
            required: true,
            unique: true,
        },
        openid:{
            type: String,
            unique:true
        },
        session_key:{
            type: String,
        },
        user_name: {
            type: String,
            default: "未设置"
        },
        password: {
            type: String,
            default:"123456",
        },
        nick_name: {
            type: String,
            default: "未知"
        },
        avatar:{
            type:String
        },
        email: {
            type: String,
            default: "未知",
        },
        phonenumber: {
            type: String,
            default: "未知"
        },
        real_name: {
            type: String,
            default: "未知"
        },
        sex: {
            type: Number,
            default: 2,
            enum: [0, 1, 2],
        },
        role: {
            type: String,
            default: "member",
            enum: ["admin", "member", "store"],
        },
        status: {
            type: Number,
            default: 1,
            enum: [0, 1],
        },
        login_ip: {
            type: String,
            default: "未知"
        },
        num_played:{
            type: Number,
            default: 0,
        },
        quit_rate:{
            type: Number,
            default: 0,
        },
        reserves_played:{
            type:[Schema.Types.ObjectId],
            ref:"Reserves"
        },
        
        login_time: {
            type: Date,
            default: Date.now,
        },
        
    },
    {
        timestamps: true, versionKey: false
    }
);


module.exports = mongoose.model("Users", UsersSchema, "Users")
